package com.atguigu.dga.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * ClassName: SpringBeanProvider
 * Package: com.atguigu.dga.util
 * Description:
 *
 * @Author:
 * @Create: 2024/3/16 15:28
 * @Version: 1.0
 */
/**
 * 提供方法：从Spring容器中获取到Bean对象assessor 也可能获取别的对象 用泛型
  */

@Component
public class SpringBeanProvider implements ApplicationContextAware {
    private ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public <T> T getBean(String beanName, Class<T> clsType) {
        T bean = applicationContext.getBean(beanName, clsType);
        return bean;
    }
}
